"use strict";

function calendar_drop(event)
	{
		console.log("ssssss");
		event.preventDefault();
//			$(event.target).removeClass("task_drag_over");
//			console.log($(event.target).attr("data-date"));
		var move_taskid,parent_taskid;
		var move_domid,parent_domid;
		move_domid=ev.dataTransfer.getData("Text");
		move_taskid=$("#"+move_domid).attr("data-taskid");
		
		console.log(move_domid);
		if($(event.target).hasClass("fc-day")){
//			$(event.target).addClass("task_drag_over");
			console.log($(event.target).attr("data-date"))
		}else{
//			$(event.target).parents("td.fc-day").addClass("task_drag_over");
			console.log($(event.target).parents("td.fc-day").attr("data-date"));
		};
			
			
		var taskid=event.id;
//			var newdate= $.fullCalendar.formatDate(event.start, "yyyy-MM-dd hh:mm");
			$.post("/index.php/task/change",
				  {
					id:event.id,
					parm1:'start_date',
					value1:newdate
				  },
				  function(dataGet,status){
			//		alert("Data: " + JSON.stringify(dataGet) + "\nStatus: " + status);
					
					if(dataGet){
						layer.msg('日期已被修改！',{time: 2000});
						$(".task[data-taskid="+taskid+"]").children('span.start_date').text(' '+newdate.substring(5,10)+' ');
					}else{
						alert("服务器修改失败，返回拖动前！\n"+dataGet.status+dataGet.message);
						revertFunc();	
					}
				  },"json");
			
			
			return false;			
	}	

$(document).ready(function(){
	$("#calendar_view").delegate('td.fc-day','dragenter',function(){
//		console.log($(event.target));
		if($(event.target).hasClass("fc-day")){
			$(event.target).addClass("task_drag_over");
//			console.log($(event.target).attr("data-date"))
		}else{
			$(event.target).parents("td.fc-day").addClass("task_drag_over");
//			console.log($(event.target).parents("td.fc-day").attr("data-date"));
		};

		
		return false;
	});
	
	$("#calendar_view").delegate('td.fc-day','dragleave',function(){
		
//		$("td.fc-day.task_drag_over").removeClass("task_drag_over");
		return false;
	});

//	$("#calendar_view").delegate('td.fc-day','drop',function(event){
	
	
	
	
	// $("#calendar_view").delegate('td.fc-day','dragover',function(){
			// $(event.target).removeClass("twink");
			// console.log($(event.target).attr("data-date"));
	// });

	
});